package com.ruoyi.patrol.controller;

import java.util.List;

import com.ruoyi.common.config.RuoYiConfig;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.file.FileUploadUtils;
import com.ruoyi.framework.config.ServerConfig;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtNotification;
import com.ruoyi.patrol.service.IPtNotificationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 通知公告Controller
 *
 * @author 理想三旬
 * @date 2022-11-06
 */
@RestController
@RequestMapping("/patrol/notification")
public class PtNotificationController extends BaseController {
    @Autowired
    private IPtNotificationService ptNotificationService;

    /**
     * 查询通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtNotification ptNotification) {
        startPage();
        List<PtNotification> list = ptNotificationService.selectPtNotificationList(ptNotification);
        return getDataTable(list);
    }

    /**
     * 查询通知公告列表（不分页，不带查询参数）
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:list')")
    @GetMapping("/list/nopage")
    public List<PtNotification> listNotificationNoPage() {
        List<PtNotification> list = ptNotificationService.selectPtNotificationListNoPage();
        return list;
    }

    /**
     * 导出通知公告列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:export')")
    @Log(title = "通知公告", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtNotification ptNotification) {
        List<PtNotification> list = ptNotificationService.selectPtNotificationList(ptNotification);
        ExcelUtil<PtNotification> util = new ExcelUtil<PtNotification>(PtNotification.class);
        return util.exportExcel(list, "notification");
    }

    /**
     * 获取通知公告详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(ptNotificationService.selectPtNotificationById(id));
    }

    /**
     * 新增通知公告
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:add')")
    @Log(title = "通知公告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtNotification ptNotification) {
        ptNotification.setCreateBy(SecurityUtils.getUsername());
        return toAjax(ptNotificationService.insertPtNotification(ptNotification));
    }

    /**
     * 修改通知公告
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:edit')")
    @Log(title = "通知公告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtNotification ptNotification) {
        return toAjax(ptNotificationService.updatePtNotification(ptNotification));
    }

    /**
     * 撤回通知公告
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("recall/{ids}")
    public AjaxResult recall(@PathVariable String[] ids) {
        return toAjax(ptNotificationService.deletePtNotificationByIds(ids, 1));
    }

    /**
     * 删除通知公告
     */
    @PreAuthorize("@ss.hasPermi('patrol:notification:remove')")
    @Log(title = "通知公告", businessType = BusinessType.DELETE)
    @DeleteMapping("remove/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(ptNotificationService.deletePtNotificationByIds(ids, 2));
    }


}
